package com.jmxcfc.blfsc.common.common;

import com.jmxcfc.blfsc.common.common.enums.BaseErrorEnum;
import com.jmxcfc.blfsc.common.common.request.BaseRequest;
import com.jmxcfc.blfsc.common.common.response.BaseResponse;
import com.jmxcfc.blfsc.common.exception.InitResponseException;
import com.jmxcfc.blfsc.common.common.enums.ProcessStateEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 初始化响应实体
 * T: BaseResponse响应体T
 * B: BaseRequest请求体B
 * @author zhuyiping
 */
public interface IResponseService<T,B> {

    Logger logger = LoggerFactory.getLogger(IResponseService.class);

    /**
     * 初始化transResponse
     *
     * @param baseRequest
     * @param baseResponse
     * @throws InitResponseException
     */
    default void initResponse(BaseRequest<B> baseRequest, BaseResponse<T> baseResponse) throws InitResponseException {
        try {
            baseResponse.getHeader().setRequestNo(baseRequest.getHeader().getRequestNo());
            //批次号或者任务id(流水号、序列号含义)业务流水号
            baseResponse.getHeader().setSerialSeq(baseRequest.getHeader().getSerialSeq());
            baseResponse.getHeader().setProcessState(ProcessStateEnum.PROCESSING);
            baseResponse.getHeader().setResCode(BaseErrorEnum.START.getValue());
            baseResponse.getHeader().setResMessage(BaseErrorEnum.START.getMsg());
        } catch (Exception e) {
            throw new InitResponseException(e.getMessage());
        }
    }
}
